package offer;

import slidingWindowAlgorithm.review4_20.Class3;

import java.util.HashMap;

public class Offer48 {

    public int lengthOfLongestSubstring(String s) {
        HashMap<Character, Integer> window = new HashMap<>();

        int left=0,right=0;
        int res=0;
        int size = s.length();

        while (right<size){
            char c = s.charAt(right);
            window.put(c,window.getOrDefault(c,0)+1);
             right++;
            while (window.get(c)>1){
                char c1 = s.charAt(left);
                left++;
                window.put(c1,window.get(c1)-1);
            }
            res= Math.max(res,right-left);
        }
        return  res;
    }

    public static void main(String[] args) {
        Offer48 offer48 = new Offer48();
        System.out.println(offer48.lengthOfLongestSubstring("abcabcbb"));


    }
}
